Skip to content

fix: update TopicUpdateTransaction to use Key instead of PublicKey #2241

Merged
exploreriii merged 2 commits into
hiero-ledger:mainfrom
oGranny:fix/2214-update-TopicUpdateTransaction-use-Key
May 6, 2026
Merged

fix: update TopicUpdateTransaction to use Key instead of PublicKey #2241
exploreriii merged 2 commits into
hiero-ledger:mainfrom
oGranny:fix/2214-update-TopicUpdateTransaction-use-Key

Conversation

@oGranny

@oGranny oGranny commented May 6, 2026

Copy link
Copy Markdown
Contributor

Description:
Update the TopicUpdateTransaction class to accept the generic Key interface for all key-related fields instead of PublicKey

Related issue(s):

Fixes #2214

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

…r key parameters

Signed-off-by: oGranny <ogranny.github.io@gmail.com>
Copilot AI review requested due to automatic review settings May 6, 2026 03:45
@oGranny
oGranny requested review from a team as code owners May 6, 2026 03:45
@codacy-production

codacy-production Bot commented May 6, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates TopicUpdateTransaction to accept the generic Key interface (rather than PublicKey) for all key-related fields, aligning topic update behavior with other transactions that already support PrivateKey/PublicKey interchangeably.

Changes:

  • Switched TopicUpdateTransaction key-related fields and setters from PublicKey to Key.
  • Updated protobuf building to use the shared key_to_proto() helper for key serialization.
  • Expanded unit tests to validate both Ed25519/ECDSA and PrivateKey/PublicKey inputs for all relevant topic update key fields.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/hiero_sdk_python/consensus/topic_update_transaction.py Migrates topic update key parameters to Key and serializes keys via key_to_proto() in the proto body builder.
tests/unit/topic_update_transaction_test.py Adds parametrized coverage for admin/submit/fee schedule/fee exempt keys using both algorithms and both private/public key inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/hiero_sdk_python/consensus/topic_update_transaction.py
Comment thread src/hiero_sdk_python/consensus/topic_update_transaction.py Outdated
Comment thread src/hiero_sdk_python/consensus/topic_update_transaction.py Outdated
@coderabbitai

coderabbitai Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@oGranny has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 42 minutes and 16 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c6f2a900-80a6-43d5-b736-3644e0700ca2

📥 Commits

Reviewing files that changed from the base of the PR and between 75ce116 and ddef21e.

📒 Files selected for processing (2)
  • src/hiero_sdk_python/consensus/topic_update_transaction.py
  • tests/unit/topic_update_transaction_test.py

Walkthrough

TopicUpdateTransaction is refactored to use the generic Key type instead of PublicKey for key-related fields (admin_key, submit_key, fee_schedule_key, fee_exempt_keys). The constructor and setters accept Key types, and protobuf serialization uses key_to_proto conversion. Support for custom fees and related fields is added.

Changes

TopicUpdateTransaction Key Type Modernization

Layer / File(s) Summary
Type & Import Surface
src/hiero_sdk_python/consensus/topic_update_transaction.py (lines 13, 24)
PublicKey import replaced with Key import; key_to_proto utility imported for Key→protobuf conversion.
Constructor & Field Initialization
src/hiero_sdk_python/consensus/topic_update_transaction.py (lines 34–41)
Constructor now accepts admin_key, submit_key, fee_schedule_key, fee_exempt_keys as Key types; adds new fields auto_renew_period, auto_renew_account, expiration_time, custom_fees with defaults; all initialized in __init__.
Setter Methods
src/hiero_sdk_python/consensus/topic_update_transaction.py (lines 96–101, 110–116, 185–191, 199–205)
set_admin_key, set_submit_key, set_fee_schedule_key, set_fee_exempt_keys updated to accept Key and list[Key] instead of PublicKey; each returns TopicUpdateTransaction for chaining.
Protobuf Assembly
src/hiero_sdk_python/consensus/topic_update_transaction.py (lines 254–275)
_build_proto_body constructs custom_fees via FixedCustomFeeList and builds fee_exempt_key_list using FeeExemptKeyList; Key fields (adminKey, submitKey, fee_schedule_key) converted via key_to_proto; other fields (autoRenewPeriod, autoRenewAccount, expirationTime, memo) assembled conditionally.
Test Helpers & Parameterized Tests
tests/unit/topic_update_transaction_test.py (lines 9–11, 31–66, 77–176)
Added create_key, get_expected_public_key, and verify_key_in_proto helpers to generate and validate keys across ed25519/ECDSA types and private/public variants. New tests test_build_topic_update_transaction_body_with_all_key_types and test_build_scheduled_topic_update_body_with_all_key_types validate all key-type combinations in proto serialization.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change—updating TopicUpdateTransaction to use Key instead of PublicKey—and is concise and specific.
Description check ✅ Passed The description is directly related to the changeset, explaining that TopicUpdateTransaction is updated to accept the generic Key interface for key-related fields and references the linked issue.
Linked Issues check ✅ Passed The PR meets the core objectives from #2214: Key replaces PublicKey in all key-related fields, constructor and setters are updated, key_to_proto handles serialization, docstrings reference Key, and tests cover both PrivateKey and PublicKey instances.
Out of Scope Changes check ✅ Passed All changes are scoped to TopicUpdateTransaction and its test file, directly addressing the key migration from PublicKey to Key. No unrelated modifications are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📋 Issue Planner

Built with CodeRabbit's Coding Plans for faster development and fewer bugs.

View plan used: #2214

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hiero_sdk_python/consensus/topic_update_transaction.py (1)

96-122: 🧹 Nitpick | 🔵 Trivial | 💤 Low value

Polish setter docstrings to match the new Key contract.

Two small inconsistencies introduced by the refactor:

  1. The phrase "Sets the public admin/submit key for the topic." (lines 98, 112) is now inaccurate — the parameter is the generic Key type and may be a PrivateKey, PublicKey, or any future SDK Key subclass. Only the public-key bytes are serialized to the wire (via key_to_prototo_proto_key()), but the API itself no longer constrains callers to public keys.
  2. The Args entries on lines 101 and 115 are malformed — they list the type in place of the parameter name. Lines 190 and 204 already use the correct key (Key): … / keys (list[Key]): … form, so these two stand out.
📝 Proposed docstring corrections
     def set_admin_key(self, key: Key) -> TopicUpdateTransaction:
         """
-        Sets the public admin key for the topic.
+        Sets the admin key for the topic. Accepts any ``Key`` (e.g. ``PrivateKey``
+        or ``PublicKey``); only the public form is serialized on the wire.

         Args:
-            Key: The admin key to set.
+            key (Key): The admin key to set.
     def set_submit_key(self, key: Key) -> TopicUpdateTransaction:
         """
-        Sets the public submit key for the topic.
+        Sets the submit key for the topic. Accepts any ``Key`` (e.g. ``PrivateKey``
+        or ``PublicKey``); only the public form is serialized on the wire.

         Args:
-            Key: The submit key to set.
+            key (Key): The submit key to set.

Also applies to: 185-211


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8ae67766-cd8d-4500-928a-ce4f1a8afec4

📥 Commits

Reviewing files that changed from the base of the PR and between 79b34a7 and 75ce116.

📒 Files selected for processing (2)
  • src/hiero_sdk_python/consensus/topic_update_transaction.py
  • tests/unit/topic_update_transaction_test.py

Comment thread tests/unit/topic_update_transaction_test.py
Comment thread tests/unit/topic_update_transaction_test.py
Comment thread tests/unit/topic_update_transaction_test.py
Signed-off-by: oGranny <ogranny.github.io@gmail.com>
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

Hello, this is the OfficeHourBot.

This is a reminder that the Hiero Python SDK Office Hours are scheduled in approximately 4 hours (14:00 UTC).

This session provides an opportunity to ask questions regarding this Pull Request.

Details:

Disclaimer: This is an automated reminder. Please verify the schedule here for any changes.

From,
The Python SDK Team

@github-actions github-actions Bot added lang: python Uses Python programming language skill: intermediate requires some knowledge of the codebase with some defined steps to implement or examples labels May 6, 2026
@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2241   +/-   ##
=======================================
  Coverage   93.73%   93.73%           
=======================================
  Files         145      145           
  Lines        9482     9483    +1     
=======================================
+ Hits         8888     8889    +1     
  Misses        594      594           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@manishdait manishdait added the step: 2nd second stage of the review approval process label May 6, 2026
@exploreriii
exploreriii merged commit 34d9e8a into hiero-ledger:main May 6, 2026
29 checks passed
@exploreriii

Copy link
Copy Markdown
Contributor

Thank you @oGranny !

@manishdait manishdait added this to the v0.2.7 milestone May 8, 2026
NssGourav pushed a commit to NssGourav/hiero-sdk-python that referenced this pull request May 14, 2026
manishdait pushed a commit to manishdait/hiero-sdk-python that referenced this pull request May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lang: python Uses Python programming language skill: intermediate requires some knowledge of the codebase with some defined steps to implement or examples step: 2nd second stage of the review approval process

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update TopicUpdateTransaction to use Key instead of PublicKey

4 participants